package com.wanpinghui.supplier.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.wanpinghui.supplier.Config;
import com.wanpinghui.supplier.object.HomePageActivity;
import com.wanpinghui.supplier.object.ObjectListActivity;
import com.yunshl.yunshllibrary.manager.MActivityManager;

/***
 * 功能描述:
 * 作者:qiujialiu
 * 时间:2017/11/30
 ***/

public class ActivityJumpUtil {
    public static void startObjectList(Context context) {
        if (Config.VERSION < 3) {
            if (MActivityManager.getInstance().haveActivity(HomePageActivity.class)) {
                try {
                    Activity activityNew = MActivityManager.getInstance().getActivity(HomePageActivity.class);
                    if (activityNew != null) {
                        ((HomePageActivity) activityNew).goPage(Config.getObjectPage());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                MActivityManager.getInstance().deleteTopThis(HomePageActivity.class);
            } else {
                Intent intent = new Intent(context, HomePageActivity.class);
                context.startActivity(intent);
            }
        }else {
            Intent intent = new Intent(context, ObjectListActivity.class);
            context.startActivity(intent);
        }
        if (context instanceof Activity) {
            ((Activity) context).finish();
        }
    }

    public static void startProductList(Context context) {
        if (MActivityManager.getInstance().haveActivity(HomePageActivity.class)) {
            try {
                Activity activityNew = MActivityManager.getInstance().getActivity(HomePageActivity.class);
                if (activityNew != null) {
                    ((HomePageActivity) activityNew).goPage(Config.getProductPage());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            MActivityManager.getInstance().deleteTopThis(HomePageActivity.class);
        } else {
            Intent intent = new Intent(context, HomePageActivity.class);
            context.startActivity(intent);
        }
        if (context instanceof Activity) {
            ((Activity) context).finish();
        }
    }
}
